package com.zretc.device.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.zretc.device.dao.Device_InDao;
import com.zretc.device.entity.Device_In;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Device_InModDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txtDevCode;
	private JTextField txtInDate;
	private JTextField txtProvider;
	private JTextField txtProTele;
	private JTextField txtInNum;
	private JTextField txtPrice;
	private JTextField txtBuyer;
	private JTextField txtInid;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Device_InModDialog dialog = new Device_InModDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Device_InModDialog() {
		setBounds(100, 100, 738, 562);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel label = new JLabel("入库修改");
			label.setFont(new Font("宋体", Font.PLAIN, 40));
			label.setBounds(282, 33, 182, 47);
			contentPanel.add(label);
		}
		{
			txtDevCode = new JTextField();
			txtDevCode.setFont(new Font("宋体", Font.PLAIN, 25));
			txtDevCode.setColumns(10);
			txtDevCode.setBounds(313, 142, 250, 30);
			contentPanel.add(txtDevCode);
		}
		{
			JLabel label = new JLabel("设备编号");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 142, 120, 30);
			contentPanel.add(label);
		}
		{
			txtInDate = new JTextField();
			txtInDate.setFont(new Font("宋体", Font.PLAIN, 25));
			txtInDate.setColumns(10);
			txtInDate.setBounds(313, 188, 250, 30);
			contentPanel.add(txtInDate);
		}
		{
			JLabel label = new JLabel("入库时间");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 188, 120, 30);
			contentPanel.add(label);
		}
		{
			txtProvider = new JTextField();
			txtProvider.setFont(new Font("宋体", Font.PLAIN, 25));
			txtProvider.setColumns(10);
			txtProvider.setBounds(313, 231, 250, 30);
			contentPanel.add(txtProvider);
		}
		{
			JLabel label = new JLabel("供 应 商");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 231, 120, 30);
			contentPanel.add(label);
		}
		{
			txtProTele = new JTextField();
			txtProTele.setFont(new Font("宋体", Font.PLAIN, 25));
			txtProTele.setColumns(10);
			txtProTele.setBounds(313, 274, 250, 30);
			contentPanel.add(txtProTele);
		}
		{
			JLabel label = new JLabel("供应商电话");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 274, 133, 30);
			contentPanel.add(label);
		}
		{
			JLabel label = new JLabel("入库数量");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 317, 106, 30);
			contentPanel.add(label);
		}
		{
			txtInNum = new JTextField();
			txtInNum.setFont(new Font("宋体", Font.PLAIN, 25));
			txtInNum.setColumns(10);
			txtInNum.setBounds(313, 317, 250, 30);
			contentPanel.add(txtInNum);
		}
		{
			JLabel label = new JLabel("设备单价");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 360, 120, 30);
			contentPanel.add(label);
		}
		{
			txtPrice = new JTextField();
			txtPrice.setFont(new Font("宋体", Font.PLAIN, 25));
			txtPrice.setColumns(10);
			txtPrice.setBounds(313, 360, 250, 30);
			contentPanel.add(txtPrice);
		}
		{
			JLabel label = new JLabel("采 购 员");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 403, 120, 30);
			contentPanel.add(label);
		}
		{
			txtBuyer = new JTextField();
			txtBuyer.setFont(new Font("宋体", Font.PLAIN, 25));
			txtBuyer.setColumns(10);
			txtBuyer.setBounds(313, 403, 250, 30);
			contentPanel.add(txtBuyer);
		}
		{
			JButton button = new JButton("取消");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			button.setFont(new Font("宋体", Font.PLAIN, 25));
			button.setBounds(214, 452, 150, 38);
			contentPanel.add(button);
		}
		{
			JButton button = new JButton("确认修改");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			button.setFont(new Font("宋体", Font.PLAIN, 25));
			button.setBounds(400, 452, 150, 38);
			contentPanel.add(button);
		}
		{
			txtInid = new JTextField();
			txtInid.setFont(new Font("宋体", Font.PLAIN, 25));
			txtInid.setColumns(10);
			txtInid.setBounds(313, 99, 250, 30);
			contentPanel.add(txtInid);
		}
		{
			JLabel label = new JLabel("入库编号");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 99, 120, 30);
			contentPanel.add(label);
		}
	}

	/**
	 * 带参构造
	 */
	public Device_InModDialog(Device_In devIn) {
		setBounds(100, 100, 738, 562);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel label = new JLabel("入库修改");
			label.setFont(new Font("宋体", Font.PLAIN, 40));
			label.setBounds(282, 33, 182, 47);
			contentPanel.add(label);
		}
		{
			txtDevCode = new JTextField();
			txtDevCode.setFont(new Font("宋体", Font.PLAIN, 25));
			txtDevCode.setColumns(10);
			txtDevCode.setBounds(313, 142, 250, 30);
			contentPanel.add(txtDevCode);
		}
		{
			JLabel label = new JLabel("设备编号");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 142, 120, 30);
			contentPanel.add(label);
		}
		{
			txtInDate = new JTextField();
			txtInDate.setFont(new Font("宋体", Font.PLAIN, 25));
			txtInDate.setColumns(10);
			txtInDate.setBounds(313, 188, 250, 30);
			contentPanel.add(txtInDate);
		}
		{
			JLabel label = new JLabel("入库时间");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 188, 120, 30);
			contentPanel.add(label);
		}
		{
			txtProvider = new JTextField();
			txtProvider.setFont(new Font("宋体", Font.PLAIN, 25));
			txtProvider.setColumns(10);
			txtProvider.setBounds(313, 231, 250, 30);
			contentPanel.add(txtProvider);
		}
		{
			JLabel label = new JLabel("供 应 商");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 231, 120, 30);
			contentPanel.add(label);
		}
		{
			txtProTele = new JTextField();
			txtProTele.setFont(new Font("宋体", Font.PLAIN, 25));
			txtProTele.setColumns(10);
			txtProTele.setBounds(313, 274, 250, 30);
			contentPanel.add(txtProTele);
		}
		{
			JLabel label = new JLabel("供应商电话");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 274, 133, 30);
			contentPanel.add(label);
		}
		{
			JLabel label = new JLabel("入库数量");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 317, 106, 30);
			contentPanel.add(label);
		}
		{
			txtInNum = new JTextField();
			txtInNum.setFont(new Font("宋体", Font.PLAIN, 25));
			txtInNum.setColumns(10);
			txtInNum.setBounds(313, 317, 250, 30);
			contentPanel.add(txtInNum);
		}
		{
			JLabel label = new JLabel("设备单价");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 360, 120, 30);
			contentPanel.add(label);
		}
		{
			txtPrice = new JTextField();
			txtPrice.setFont(new Font("宋体", Font.PLAIN, 25));
			txtPrice.setColumns(10);
			txtPrice.setBounds(313, 360, 250, 30);
			contentPanel.add(txtPrice);
		}
		{
			JLabel label = new JLabel("采 购 员");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 403, 120, 30);
			contentPanel.add(label);
		}
		{
			txtBuyer = new JTextField();
			txtBuyer.setFont(new Font("宋体", Font.PLAIN, 25));
			txtBuyer.setColumns(10);
			txtBuyer.setBounds(313, 403, 250, 30);
			contentPanel.add(txtBuyer);
		}

		{
			txtInid = new JTextField();
			txtInid.setFont(new Font("宋体", Font.PLAIN, 25));
			txtInid.setColumns(10);
			txtInid.setBounds(313, 99, 250, 30);
			contentPanel.add(txtInid);
		}
		{
			JLabel label = new JLabel("入库编号");
			label.setFont(new Font("宋体", Font.PLAIN, 25));
			label.setBounds(179, 99, 120, 30);
			contentPanel.add(label);
		}
		if (devIn != null) {
			// 给文本框赋值
			txtInid.setText(Integer.toString(devIn.getIn_id()));
			txtDevCode.setText(devIn.getDevice_code());
			txtInDate.setText(devIn.getIn_date());
			txtProvider.setText(devIn.getProvider());
			txtProTele.setText(devIn.getProvider_tele());
			txtInNum.setText(Integer.toString(devIn.getIn_num()));
			txtPrice.setText(Double.toString(devIn.getPrice()));
			txtBuyer.setText(devIn.getBuyer());
		}
		{
			JButton button = new JButton("取消");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					//隐藏
					setVisible(false);
				}
			});
			button.setFont(new Font("宋体", Font.PLAIN, 25));
			button.setBounds(214, 452, 150, 38);
			contentPanel.add(button);
		}
		{
			JButton button = new JButton("确认修改");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String tin_id = txtInid.getText();
					String device_code = txtDevCode.getText();
					String in_date = txtInDate.getText();
					String provider = txtProvider.getText();
					String tprovider_tele = txtProTele.getText();
					String tin_num = txtInNum.getText();
					String tprice = txtPrice.getText();
					String buyer = txtBuyer.getText();
					// 判断输入的值
					if (tin_id.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "入库编号不能为空");
					} else if (device_code.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "设备编号不能为空");
					} else if (in_date.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "入库日期不能为空");
					} else if (provider.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "供应商不能为空");
					} else if (tprovider_tele.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "供应商电话不能为空");
					} else if (tprice.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "设备单价不能为空");
					} else if (buyer.equals("")) {
						// 弹窗提示
						JOptionPane.showMessageDialog(null, "采购员姓名不能为空");
					} else {
						// 转型
						int in_id = Integer.parseInt(tin_id);
						int in_num = Integer.parseInt(tin_num);
						Double price = Double.parseDouble(tprice);
						// 创建对象
						Device_In di = new Device_In(in_id, device_code, in_date, tprovider_tele, tprovider_tele, in_num,
								price, buyer);
						Device_InDao did = new Device_InDao();
						boolean flag = did.modDevIn(di);
						if (flag) {
							JOptionPane.showMessageDialog(null, "修改成功");
						} else {
							JOptionPane.showMessageDialog(null, "修改失败");
						}
					}
				}
			});
			button.setFont(new Font("宋体", Font.PLAIN, 25));
			button.setBounds(400, 452, 150, 38);
			contentPanel.add(button);
		}
		// 居中
		setLocationRelativeTo(null);
	}
}
